﻿Option Strict On
Option Infer On
Option Explicit On

Imports System
Imports GenDotNet.Task.Common

Namespace StoredProcModel

   Public Enum OrderByDirection
      Unknown = 0
      Ascending
      Descending
   End Enum

   Public Module OrderByDirectionExtensions
      <System.Runtime.CompilerServices.Extension()> _
      Public Function Output(ByVal OrderByDirection As OrderByDirection) As String
         If OrderByDirection = StoredProcModel.OrderByDirection.Ascending Then
            Return "Asc"
         Else
            Return "DESC"
         End If
         Return OrderByDirection.ToString()
      End Function

      Public Function ParseOrderByDirection(ByVal value As String) As OrderByDirection
         If value.EqualsIgnoreCase("ASC") Then
            Return OrderByDirection.Ascending
         ElseIf value.EqualsIgnoreCase("ASCENDING") Then
            Return OrderByDirection.Ascending
         ElseIf value.EqualsIgnoreCase("DESC") Then
            Return OrderByDirection.Descending
         ElseIf value.EqualsIgnoreCase("DESCENDING") Then
            Return OrderByDirection.Descending
         ElseIf String.IsNullOrEmpty(value) Then
            Return OrderByDirection.Ascending
         End If
      End Function

   End Module

End Namespace

